<template>
	<div class="modal-container" v-if="show" @click.stop="cancel(2)">
		<div class="modal-content">
			<div class="modal-head modal-title-padding">
				<slot name="modal-head"></slot>
			</div>
			<div class="modal-body">
				<slot name="modal-body"></slot>
			</div>
			<div class="modal-footer">
				<div class="modal-col" hover-class="modal-hover" v-if="cancelText" @click.stop="cancel('cancel')">
					<text :style="cancelStyle" class="modal-row-text">{{cancelText}}</text>
				</div>
				<div :style="confirmStyle" class="modal-col modal-confirm" hover-class="modal-hover" @click.stop="confirm">
					<text :style="confirmStyle" class="modal-row-text">{{confirmText}}</text>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	export default {
		name: 'modal',
		props: {
			//默认是否显示
			show: {
				type: Boolean,
				default: true
			},
			//取消按钮文字
			cancelText: {
				type: String,
				default: ''
			},
			//取消样式
			cancelStyle: {
				type: [String, Object]
			},
			//确定按钮文字
			confirmText: {
				type: String,
				default: '确定'
			},
			//确定样式
			confirmStyle: {
				type: [String, Object]
			},
			//阻止点击对话框外侧锁屏
			disableScreenClick: {
				type: Boolean,
				default: false
			}
		},
		methods: {
			confirm() {
				this.$emit('confirm')
			},
			cancel(type) {
				if (!this.disableScreenClick || type === 'cancel') {
					this.$emit('cancel')
				}
			}
		}
	}
</script>
<style  scoped>


	.modal-container {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 999;
		background-color: rgba( 0,0,0, .6);
		transition: all 5s;
		display: flex;
		align-items: center;
		justify-content: center;

		.modal-content {
			width: 80%;
			border-radius: 26rpx;
			background: #FFFFFF;
			overflow: hidden;
			animation: fadeZoom .15s linear;

			.modal-head {
				padding: 30rpx 30rpx 0;
				text-align: center;
				color: #000;
				font-size: $fontSizeLg;
				font-weight: 700;
			}

			.modal-title-padding {
				padding-bottom: 30rpx;
			}

			.modal-body {
				overflow:auto;
				padding: 40rpx 30rpx;
				font-size: $fontSizeSm;
				color: #000;
				text-align: center;
			}

			.modal-footer {
				display: flex;
				position: relative;
				text-align: center;
				font-size: $fontSizeLg;
				line-height: 100rpx;
				color: #007AFF;
				border-top: 0.5px solid rgba(9, 20, 31, 0.13);

				.modal-col {
					flex: 1;
					width: 100%;
					position: relative;
				}

				.modal-col:first-child::after {
					content: '';
					position: absolute;
					top: 0;
					bottom: 0;
					right: 0;
					border-right: 1px solid rgba(9, 20, 31, 0.13);
					transform: scaleX(.36);
				}

				.modal-confirm {
					color: rgb(0, 122, 255);
				}

				.modal-hover {
					background-color: #f2f2f2;
				}
			}

			.modal-footer::after {
				content: '';
				position: absolute;
				left: 0;
				right: 0;
				top: 0;
				border-top: 0.5px solid rgba(9, 20, 31, 0.13);
				transform: scaleY(.36);
			}
		}

		@keyframes fadeZoom {
			0% {
				transform: scale(.7);
				opacity: .6;
			}

			80% {
				transform: scale(1.2);
				opacity: .3;
			}

			100% {
				transform: scale(1);
				opacity: 1;
			}
		}
	}
</style>